
import {
  getTradingData,
  getPeopleCountData,
  getChartLineBar,
  getCheckReportData,
  getSixTypeData,
  getNJWeather,
  getChartLineBarNew,
  getChartLineBarEpayNew,
  getSixTypeDataNew,
  fetchMarketDailyTopType,
  fetchMarketDailyHostSales,
  fetchMarketDailyBusinessTop10,
  fetchMarketMonthlySales,
  fetchMarketDailyVisitInterval,
  fetchMarketDailyFlowFunnel,
  fetchMarketDailySales,
  fetchMarketDailyCheckInfo,
  fetchMarketMontlyFlowTrend,
  fetchMarketDailyFaceAgeHour,
  getTargetInfo,
  getTargetSave,
  getfenshishuju
} from "@/api/home";

import{
  getRegionalChartsData
} from '@/api/peopleNumber'
import { formatDate3 } from "@/utils"
import * as types from '../../mutation-types'
export default {
  namespaced: true, // 封闭
  state: {
    options: {},
    TOPTYPE_PTC_DATA: {},
    MARKET_DAILY_TOPTYPE_SALSE_DATA:{},
    MARKET_DAILY_HOT_SALES:{},
    MARKET_DAILY_HOT_REGIONAL:{},
    MARKET_DAILY_VISIT_INTERVAL:{},
    MARKET_DAILY_FLOW_FUNNEL:{},
    MARKET_MONTHLY_SALES_PER:{},
    MARKET_MONTHLY_FLOW_TREND:{},
    MARKET_DAILY_FACE_AGE_HOUR:{},
    sixTypeOptions: {},
    salesRat: 0,
    peopleRat: 0

  },
  mutations: {
    // 分时数据
    [types.SET_CHART_DATA](state, options) {
      state.options = options
    },
    // 六大类占比数据
    [types.SET_SIX_TYPE_DATA](state, options) {
      state.sixTypeOptions = options
    },

    [types.SET_TOPTYPE_PTC_DATA](state, options) {
      state.TOPTYPE_PTC_DATA = options
    },

    [types.SET_MARKET_DAILY_TOPTYPE_SALSE_DATA](state, options){
      state.MARKET_DAILY_TOPTYPE_SALSE_DATA = options
    },
    [types.SET_MARKET_DAILY_HOT_SALES](state, options){
      state.MARKET_DAILY_HOT_SALES = options
    },
    [types.SET_MARKET_DAILY_HOT_REGIONAL](state, options){
      state.MARKET_DAILY_HOT_REGIONAL = options
    },
    [types.SET_MARKET_DAILY_VISIT_INTERVAL](state, options){
      state.MARKET_DAILY_VISIT_INTERVAL = options
    },
    [types.SET_MARKET_DAILY_FLOW_FUNNEL](state, options){
      state.MARKET_DAILY_FLOW_FUNNEL = options
    },
    [types.SET_MARKET_MONTHLY_SALES_PER](state, options){
      state.MARKET_MONTHLY_SALES_PER = options
    },
    [types.SET_MARKET_MONTHLY_FLOW_TREND](state, options){
      state.MARKET_MONTHLY_FLOW_TREND = options
    },
    [types.SET_MARKET_DAILY_FACE_AGE_HOUR](state, options){
      state.MARKET_DAILY_FACE_AGE_HOUR = options
    },

    [types.SALES_RAT](state, salesRat) {
      state.SALES_RAT = salesRat
    },
    [types.PEOPLE_RAT](state, peopleRat) {
      state.PEOPLE_RAT = peopleRat
    }
  },
  getters: {},
  actions: {
    // 编辑小目标
    async fetchTargetInfo(context, payload) {
      const { marketId, date } = payload;
      try {
        const { data } = await getTargetInfo(marketId, date);
        return data
      } catch (err) {
        console.log(err)
      }
    },
    async fetchTargetSave(context, payload) {
      const { marketId, date, marketTargetId,personNumber,orderAmount } = payload;
      try {
        const { data } = await getTargetSave(marketId, date, marketTargetId,personNumber,orderAmount);
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取市场月度销售完成率
    async fetchMarketMonthlySales(context, payload) {
      const { marketId, year, month, orderAmount } = payload
      try {
        const { data } = await fetchMarketMonthlySales(marketId, year, month)
        console.log("orderAmount, data.Sales", orderAmount, data.Sales)
        // let rat = Math.round((data.Sales / orderAmount) * 100)


        // let rat
        // if (orderAmount === 0){
        //   rat = 0
        // }else{
        //   rat = Math.round((data.Sales / orderAmount) * 100)
        // }

        let rat = orderAmount === 0 ? 0 : Math.round((data.Sales / orderAmount) * 100)

        const options = {
          tooltip: {
            formatter: '{a} <br/>{b} : {c}%'
          },
          series: [
            {
              name: '完成率',
              type: 'gauge',
              detail: {formatter: '{value}%'},
              data: [{value: rat, name: '完成率'}]
            }
          ]
        };
        context.commit(types.SET_MARKET_MONTHLY_SALES_PER, options)
        context.commit(types.SALES_RAT, rat)
        return rat
      } catch (err) {
        console.log('modules-home-index.js-fetchMarketMonthlySales', err)
      }
    },

    async fetchMarketMontlyFlowTrend(context, payload) {
      const { year, month, personNumber } = payload
      try {
        const { data } = await fetchMarketMontlyFlowTrend(year, month)
        // let rat = Math.round((data.totalFlowCount / personNumber) * 100)

        // let rat
        // if (personNumber === 0) {
        //   rat = 0
        // } else {
        //   rat = Math.round((data.totalFlowCount / personNumber) * 100)
        // }

        let rat = personNumber === 0 ? 0 : Math.round((data.totalFlowCount / personNumber) * 100)
        const options = {
          tooltip: {
            formatter: '{a} <br/>{b} : {c}%'
          },
          series: [
            {
              name: '完成率',
              type: 'gauge',
              detail: { formatter: '{value}%' },
              data: [{ value: rat, name: '完成率' }]
            }
          ]
        };
        context.commit(types.SET_MARKET_MONTHLY_FLOW_TREND, options)
        context.commit(types.PEOPLE_RAT, rat)
        return rat
      } catch (err) {
        console.log(err)
      }
    },








    // 总数据看板 123
    async fetchTradingData(context, payload) {
      const { date } = payload
      try {

        const { data } = await getTradingData(date)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 总数据看板 4
    async fetchPeopleCountData(context, payload) {
      const { date } = payload
      try {
        const { data } = await getPeopleCountData(date)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 20200303

    // 获取品类客单价，分类销售占比
    // sort 1 按金额 2 按笔数
    async fetchMarketDailyTopType(context, payload) {
      const { year, month, day, marketId, sort } = payload
      try {
        const { data } = await fetchMarketDailyTopType(marketId, year, month, day) // 总金额
        let xAxis = []
        let mainSeries = []
        let paiSeries = []

        let maxSales = 0
        let maxSalesName = "N/A"
        let maxCount = 0
        let maxCountName = "N/A"
        let totalSales = 0
        let totalCount = 0
        let paiSeriesName = "金额"

        for (let i = 0; i < data.length; i ++) {
          xAxis[i] = data[i].Key
          mainSeries[i] = data[i].PCT
          if (maxSales < data[i].Sales) {
            maxSales = data[i].Sales
            maxSalesName = data[i].Key
          }
          if (maxCount < data[i].DocCount) {
            maxCount = data[i].DocCount
            maxCountName = data[i].Key
          }
          if (sort == 1 ){
            paiSeries[i] ={value: data[i].Sales / 100, name: data[i].Key}
          } else {
            paiSeriesName = "笔数"
            paiSeries[i] = {value: data[i].DocCount, name: data[i].Key}
          }
          totalSales += data[i].Sales
          totalCount += data[i].DocCount
        }

        const options1 = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
              type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              data: xAxis,
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis: [
            {
              type: 'value'
            }
          ],
          series: [
            {
              name: '客单价',
              type: 'bar',
              barWidth: '60%',
              data: mainSeries
            }
          ]
        };

        const options2 = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          legend: {
            orient: 'vertical',
            left: 'left',
            top: 'center',
            data: xAxis
          },
          series: [
            {
              name: paiSeriesName,
              type: 'pie',
              radius: '55%',
              center: ['50%', '50%'],
              data: paiSeries,
              label: {
              show: false,
              position: 'center'
            },
            labelLine: {
              show: false
            },
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
        context.commit(types.SET_TOPTYPE_PTC_DATA, options1)
        context.commit(types.SET_MARKET_DAILY_TOPTYPE_SALSE_DATA, options2)
        if (totalCount < 1) {
          totalCount = 1
        }
        if (totalSales < 1) {
          totalSales = 1
        }

        return [
          { maxSalesName: maxSalesName, maxSales: (maxSales / 100), per: Math.round(maxSales / totalSales * 100) },
          { maxCountName: maxCountName, maxCount: maxCount, per: Math.round(maxCount / totalCount * 100) }]
      } catch (err) {
        console.log('modules-home-index.js-fetchMarketDailyTopType 00', err)
      }
    },

    // 获取市场每日热销商品 单品成交排行 销售额
    async fetchMarketDailyHostSales(context, payload) {
      const { year, month, day, marketId, sort } = payload
      try {
        const { data } = await fetchMarketDailyHostSales(marketId, year, month, day, sort) // 总金额
        let xAxis = []
        let mainSeries = []
        let seriesName = "重量"
        let color = []

        if (sort == 1) {
          seriesName = "金额"
        }

        for (let i = 0; i < data.length; i ++) {
          xAxis[i] = data[i].Key
          if (sort == 1){
            mainSeries[i] = data[i].Sales/100
            color = ['#3c90f7']
          } else {
            mainSeries[i] = data[i].Weight/1000
            color = ['#3c90f7']
          }
        }

        const options = {
          color: color,
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              data: xAxis,
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis: [
            {
              type: 'value'
            }
          ],
          series: [
            {
              name: seriesName,
              type: 'bar',
              barWidth: '60%',
              data: mainSeries
            }
          ]
        };
        context.commit(types.SET_MARKET_DAILY_HOT_SALES, options)
      } catch (err) {
        console.log('modules-home-index.js-fetchMarketDailyHostSales', err)
      }
    },

    // 获取市场每日热点区域
    async fetchHotRegionalData(context, payload) {
      const { marketId, year, month, day } = payload
      console.log(year, month, day)
      let startDate =  new Date(year, month-1, day);
      let endDate = new Date(year, month-1, day, 23,59,59)
      try {
        const { data } = await getRegionalChartsData(formatDate3(startDate, "yyyy-MM-dd hh:mm:ss"), formatDate3(endDate, "yyyy-MM-dd hh:mm:ss"))
        console.log('data', data)
        let xAxis = []
        let mainSeries = []

        let rData = data.chart.list

        for (let i = 1; i < rData.length; i ++) {
          xAxis[i] = rData[i].region
          mainSeries[i] = {value: rData[i].removelDuplicateCnt, name: rData[i].region}
        }

        const options =  {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          title: {
          },
          tooltip: {
              trigger: 'item',
              formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          legend: {
              orient: 'vertical',
              left: 'left',
              top: 'center',
              data: xAxis
          },
          series: [
              {
                  name: '客流量',
                  type: 'pie',
                  radius: '70%',
                  center: ['60%', '50%'],
                  data: mainSeries,
                  label: {
                    show: false,
                    position: 'center'
                },
                labelLine: {
                    show: false
                },
                  emphasis: {
                      itemStyle: {
                          shadowBlur: 10,
                          shadowOffsetX: 0,
                          shadowColor: 'rgba(0, 0, 0, 0.5)'
                      }
                  }
              }
          ]
      };

        context.commit(types.SET_MARKET_DAILY_HOT_REGIONAL, options)
        console.log('fetchHotRegionalData', options)
      } catch (err) {
        console.log('modules-home-index.js-fetchHotRegionalData', err)
      }
    },

    async fetchMarketDailyVisitInterval(context, payload) {
      const { marketId, year, month, day } = payload
      let date =  new Date(year, month-1, day);
      try {
        const { data } = await fetchMarketDailyVisitInterval(formatDate3(date, "yyyy-MM-dd hh:mm:ss"))
        let xAxis = []
        let mainSeries = []

        for (let i = 1; i < data.length; i ++) {
          xAxis[i] = data[i].name
          mainSeries[i] = {value: data[i].cnt, name: data[i].name}
        }

        const options =  {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49'],
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            top: 'center',
            data: xAxis
        },
        series: [
            {
                name: '人数',
                type: 'pie',
                radius: ['50%', '70%'],
                center: ['60%', '50%'],
                avoidLabelOverlap: true,
                label: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    label: {
                        show: true,
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                },
                labelLine: {
                    show: false
                },
                data: mainSeries
            }
        ]
        };

        context.commit(types.SET_MARKET_DAILY_VISIT_INTERVAL, options)
      } catch (err) {
        console.log('modules-home-index.js-fetchMarketDailyVisitInterval', err)
      }
    },

    async fetchMarketDailyFlowFunnel(context, payload) {
      const { marketId, year, month, day } = payload
      let date =  new Date(year, month-1, day);
      let yestoday = new Date(year, month-1, day - 1)
      let data = {}
      let yesterdayData = {}
      try {

        const f1 = await fetchMarketDailyFlowFunnel(formatDate3(date, "yyyy-MM-dd hh:mm:ss")) // 今天
        const f2 = await fetchMarketDailyFlowFunnel(formatDate3(yestoday, "yyyy-MM-dd hh:mm:ss")) // 昨天

        await Promise.all([f1, f2]).then((result) => {
          yesterdayData = result[1].data
          data = result[0].data
        let xAxis = []
        let mainSeries = []

        let max = 1
        let min = 0
        for (let i = 0; i < data.length-1; i ++) {
          xAxis[i] = data[i].name + " " + data[i].cnt
          mainSeries[i] = {value: data[i].cnt, name: data[i].name + " " + data[i].cnt}

          if (max < data[i].cnt) {
            max = data[i].cnt
          }

          if (min > data[i].cnt){
            min = data[i].cnt
          }
        }
        const options = {
          color: ['#427eb4', '#61ae7b', '#e79f3c', '#b24434'],
          tooltip: {
              trigger: 'item',
              formatter: "{a} <br/>{b} : {c}%"
          },
          legend: {
            orient: 'vertical',
            left: 'left',
            top: 'center',
            show: false,
            data: xAxis
          },

          series: [
              {
                  name:'漏斗图',
                  type:'funnel',
                  left: '10%',
                  top: 60,
                  // x2: 80,
                  bottom: 60,
                  width: '80%',
                  // height: {totalHeight} - y - y2,
                  min: min,
                  max: max,
                  minSize: '20%',
                  maxSize: '100%',
                  sort: 'descending',
                  gap: 12,
                  label: {
                      show: true,
                      position: 'inside'
                  },
                  labelLine: {
                      length: 10,
                      lineStyle: {
                          width: 1,
                          type: 'solid'
                      }
                  },
                  itemStyle: {
                      borderColor: '#fff',
                      borderWidth: 1
                  },
                  emphasis: {
                      label: {
                          fontSize: 20
                      }
                  },
                  data: mainSeries
              }
          ]
        };
        context.commit(types.SET_MARKET_DAILY_FLOW_FUNNEL, options)
        }).catch((error) => {
          console.log(error)
        })

      } catch (err) {
        console.log('modules-home-index.js-fetchMarketDailyFlowFunnel', err)
      }
      return [data, yesterdayData]
    },

    // 获取市场每日商户销售排行榜
    async fetchMarketDailyBusinessTop10(context, payload) {
      const { year, month, day, marketId, sort } = payload
      try {
        const { data } = await fetchMarketDailyBusinessTop10(marketId, year, month, day, sort) // 总金额
        return data
      } catch (err) {
        console.log('modules-home-index.js-fetchMarketDailyBusinessTop10', err)
      }
    },

    async fetchMarketDailyFaceAgeHour(context, payload) {
      const { marketId, year, month } = payload
      try {
        const { data } = await fetchMarketDailyFaceAgeHour(year, month)
        const options = {
          color: ['#47b8e1'],
          xAxis: {
            type: 'category',
            data: ['小于20岁', '20-29岁', '30-39岁', '40-49岁', '50-59岁', '60岁以上']
          },
          yAxis: {
            type: 'value'
          },
          series: [{
            data: [data.lass_20_total_number/7, data.lass_30_total_number/7, data.lass_40_total_number/7, data.lass_50_total_number/7, data.lass_60_total_number/7, data.greater_equal_70_total_number/7],
            type: 'bar'
          }]
        };
        context.commit(types.SET_MARKET_DAILY_FACE_AGE_HOUR, options)

        return data
      } catch (err) {
        console.log(err)
      }
    },

    async fetchMarketDailySales(context, payload) {
      const { year, yesterdayMonth, month, day, marketId, yesterdayDay } = payload
      let data = {}
      let yesterdayData = {}
      try {
        const f1 = await fetchMarketDailySales(marketId, year, month, day) // 今天
        const f2 = await fetchMarketDailySales(marketId, year, yesterdayMonth, yesterdayDay) // 昨天
        await Promise.all([f1, f2]).then((result) => {
          yesterdayData = result[1].data
          data = result[0].data
        }).catch((error) => {
          console.log(error)
        })
      } catch (err) {
        console.log('modules-home-index.js-fetchMarketDailySales', err)
      }
      return [data, yesterdayData]
    },

    // 获取市场每日销售排名
    async fetchMarketDailyBusinessTop10(context, payload){
      const { year, month, day, marketId, sort } = payload
      try {
        const {data} = await fetchMarketDailyBusinessTop10(marketId, year, month, day, sort)
        return data
      } catch (err) {
        console.log('modules-home-index.js-fetchMarketDailyBusinessTop10', err)
      }
    },

    // 分时数据
    async fetchChartListNew(context, payload) {
      const { targetDate } = payload
      try {
        const { data } = await getfenshishuju(targetDate)
        let fenshiMaxSales = 0
        let fenshiMaxSalesKey = ''
        let fenshiMaxpeople = 0
        let fenshiMaxpeopleKey = ''
        let largestGroup = data.largestGroup
        let t = data.list
        for(let i=0; i<t.length; i++){
          if (fenshiMaxSales < t[i].Sales){
            fenshiMaxSales = t[i].Sales
            fenshiMaxSalesKey = t[i].Key
          }
          if (fenshiMaxpeople < t[i].TotalFlowNumber) {
            fenshiMaxpeople = t[i].TotalFlowNumber
            fenshiMaxpeopleKey = t[i].Key
          }
        }
        const options = {
          noDataLoadingOption: {
            text: '暂无数据',
            effect: 'bubble',
            effectOption: {
              effect: {
                n: 0
              }
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'cross',
              crossStyle: {
                backgroundColor: '#283b56'
              }
            }
          },
          color: ['#f65f2f', '#5ab1ef', '#f4516c'],
          legend: {
            data: ['销售额(元)', '客流量'],
            right: 100
          },
          xAxis: [
            {
              type: 'category',
              data: (() => {
                return data.list.map(item => {
                  let time = item.Key.split(" ")[1];
                  return time;
                });
              })(),
              axisPointer: {
                type: 'shadow'
              }
            }
          ],
          yAxis: [
            {
              type: 'value',
              // name: '销售额'
            },
            {
              type: 'value',
              // name: '客流量'
            }
          ],
          series: [
            {
              name: '销售额(元)',
              type: 'bar',
              data: (() => {
                return data.list.map(item => item.Sales / 100)
              })()
            },
            {
              name: '客流量',
              type: 'line',
              yAxisIndex: 1,
              data: (() => {
                return data.list.map(item => item.TotalFlowNumber)
              })()
            }
          ]
        }
        context.commit(types.SET_CHART_DATA, options)
        return {fenshiMaxSales, fenshiMaxSalesKey, fenshiMaxpeople, fenshiMaxpeopleKey, largestGroup}
      } catch (err) {
        console.log(err)
      }
    },
    // 20200303
    async fetchMarketDailyCheckInfo(context, payload){
      const { date} = payload
      try {
        const { data } = await fetchMarketDailyCheckInfo(date)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 分时数据
    async fetchChartList(context, payload) {
      const { date, isExist } = payload
      try {
        const { data } = await getChartLineBar(date)
        if (isExist === 0) {
          const options = {
            noDataLoadingOption: {
              text: '暂无数据',
              effect: 'bubble',
              effectOption: {
                effect: {
                  n: 0
                }
              }
            },
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'cross',
                crossStyle: {
                  backgroundColor: '#283b56'
                }
              },
              formatter: params => {
                let html = ''
                html += `<p>${params[0].name}</p>`
                params.map((item, index) => {
                  if (item.seriesName === '成交金额') {
                    html += `<p>${item.seriesName}: ${item.data}元</p>`
                  } else {
                    html += `<p>${item.seriesName}: ${item.data}</p>`
                  }
                })
                return html
              }
            },
            color: ['#2ec7c9', '#5ab1ef', '#f4516c'],
            legend: {
              data: ['成交金额', '成交笔数']
            },
            xAxis: [
              {
                type: 'category',
                data: (() => {
                  return data.map(item => {
                    let time = item.time.split(' ')[1]
                    time = `${time}:00`
                    return time
                  })
                })(),
                axisPointer: {
                  type: 'shadow'
                }
              }
            ],
            yAxis: [
              {
                type: 'value',
                name: '成交金额(元)'
              },
              {
                type: 'value',
                name: '成交笔数'
              }
            ],
            series: [
              {
                name: '成交金额',
                type: 'bar',
                data: (() => {
                  return data.map(item => item.totalAmount / 100)
                })()
              },
              {
                name: '成交笔数',
                type: 'line',
                yAxisIndex: 1,
                data: (() => {
                  return data.map(item => item.totalPayNumber)
                })()
              }
            ]
          }
          context.commit(types.SET_CHART_DATA, options)
        } else if (isExist === 1) {
          const options = {
            noDataLoadingOption: {
              text: '暂无数据',
              effect: 'bubble',
              effectOption: {
                effect: {
                  n: 0
                }
              }
            },
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'cross',
                crossStyle: {
                  backgroundColor: '#283b56'
                }
              },
              formatter: params => {
                let html = ''
                html += `<p>${params[0].name}</p>`
                params.map((item, index) => {
                  if (item.seriesName === '成交金额') {
                    html += `<p>${item.seriesName}: ${item.data}元</p>`
                  } else {
                    html += `<p>${item.seriesName}: ${item.data}</p>`
                  }
                })
                return html
              }
            },
            color: ['#2ec7c9', '#5ab1ef', '#f4516c'],
            legend: {
              data: ['成交金额', '成交笔数', '客流量']
            },
            xAxis: [
              {
                type: 'category',
                data: (() => {
                  return data.map(item => {
                    let time = item.time.split(' ')[1]
                    time = `${time}:00`
                    return time
                  })
                })(),
                axisPointer: {
                  type: 'shadow'
                }
              }
            ],
            yAxis: [
              {
                type: 'value',
                name: '成交金额(元)'
              },
              {
                type: 'value',
                name: '成交笔数/客流量'
              }
            ],
            series: [
              {
                name: '成交金额',
                type: 'bar',
                data: (() => {
                  return data.map(item => item.totalAmount / 100)
                })()
              },
              {
                name: '客流量',
                type: 'line',
                yAxisIndex: 1,
                data: (() => {
                  return data.map(item => item.totalPeopleNumber)
                })()
              },
              {
                name: '成交笔数',
                type: 'line',
                yAxisIndex: 1,
                data: (() => {
                  return data.map(item => item.totalPayNumber)
                })()
              }
            ]
          }
          context.commit(types.SET_CHART_DATA, options)
        }
      } catch (err) {
        console.log(err)
      }
    },
    // 检测信息
    async fetchCheckReportData(context, payload) {
      const { date, perPage, page } = payload
      try {
        const { data } = await getCheckReportData(date, perPage, page)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 20200303


    // 六大类占比数据
    async fetchSixTypeDataNew(context, payload) {
      const { marketId } = payload
      try {
        const { data } = await getSixTypeDataNew(marketId)
        const options = {
          tooltip: {},
          legend: {
            data: ['交易额 (元)'],
            x: 'right'
          },
          color: ['#2ec7c9'],
          radar: {
            // shape: 'circle',
            name: {
              textStyle: {
                color: '#000'
              }
            },
            indicator: (() => {
              return data.map(item => ({ name: item.businessTypeName, max: 30000 }))
            })()
          },
          series: [{
            name: '交易额 (元)',
            type: 'radar',
            areaStyle: { normal: { color: '#2ec7c9' }},
            data: [
              {
                value: (() => {
                  return data.map(item => item.saleAmount / 100)
                })(),
                name: '交易额 (元)'
              }
            ]
          }]
        }
        context.commit(types.SET_SIX_TYPE_DATA, options)
      } catch (err) {
        console.log(err)
      }
    },

    // 20200303
    // 六大类占比数据
    async fetchSixTypeData(context, payload) {
      const { date } = payload
      try {
        const { data } = await getSixTypeData(date)
        const options = {
          tooltip: {},
          legend: {
            data: ['交易额 (元)'],
            x: 'right'
          },
          color: ['#2ec7c9'],
          radar: {
            // shape: 'circle',
            name: {
              textStyle: {
                color: '#000'
              }
            },
            indicator: (() => {
              return data.map(item => ({ name: item.businessTypeName, max: 30000 }))
            })()
          },
          series: [{
            name: '交易额 (元)',
            type: 'radar',
            areaStyle: { normal: { color: '#2ec7c9' }},
            data: [
              {
                value: (() => {
                  return data.map(item => item.saleAmount / 100)
                })(),
                name: '交易额 (元)'
              }
            ]
          }]
        }
        context.commit(types.SET_SIX_TYPE_DATA, options)
      } catch (err) {
        console.log(err)
      }
    },
    // 获取南京天气数据
    async fetchNJWeather(context, payload) {
      const { date } = payload
      try {
        const { data } = await getNJWeather(date)
        return data
      } catch (err) {
        console.log(err)
      }
    }
  }
}
